package com.dao.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.dao.LoginDao;
import com.entity.User;

@Repository("loginDao")
public class LoginDaoImpl extends HibernateDaoSupport implements LoginDao {
	
	Session sesstion=null;

	@SuppressWarnings("unchecked")
	public List<User> getUserByUsername(String username) throws Exception {
		sesstion=getSession();
		Criteria c=sesstion.createCriteria(User.class);
		if(!(username.trim().equals("")||username==null))
		  c.add(Restrictions.eq("email", username));
	 return (List<User>)c.list();
	}

	 @Transactional(propagation = Propagation.REQUIRED,readOnly=false)
	public void saveUser(User user) throws Exception {
		getHibernateTemplate().save(user);
	}

	 @Transactional(propagation = Propagation.REQUIRED)
	public void updateUser(User user) throws Exception {
		 getHibernateTemplate().update(user);
	}


}
